<template>
  <j-modal
    :confirmLoading="confirmLoading"
    :ok=false
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    :title="title"
    :visible="visible"
    :width="500"
    cancelText="关闭"
    switchFullscreen
    @cancel="handleCancel"
    @ok="handleOk">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :hidden="false"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单编号"
        >
          <a-input v-decorator="['sfaOrderCode']" :disabled="true"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="经销商编号">
          <a-input v-decorator="['customerCode']" :disabled="true"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="经销商名称">
          <a-input v-decorator="['customerName']" :disabled="true" :min="0"
                          placeholder="请输入" style="width:100%"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="物流公司">
          <a-input v-decorator="['logisticsCompany']" :disabled="disableSubmit" :min="0"
                          placeholder="请输入" style="width:100%"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="物流单号">
          <a-input v-decorator="['logisticsNo',validatorRules.logisticsNo]" :disabled="disableSubmit" placeholder="请输入"
                          style="width:100%"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="物流详情">
          <a-input v-decorator="['logisticsDetails']" :disabled="disableSubmit" placeholder="请输入"
                   style="width:100%"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, postAction } from '@/api/manage'
import { queryDepartTreeList, queryIdTree } from '@/api/api'
import { pick } from 'lodash'
import ATextarea from 'ant-design-vue/es/input/TextArea'

export default {
  name: 'SysDepartModal',
  components: { ATextarea, },
  data() {
    return {
      listUrl: '/cnUserController/getPageList',
      departTree: [],
      orgTypeData: [],
      terminalTargetList: [{}],
      phoneWarning: '',
      title: '操作',
      isAll: false,
      seen: false,
      visible: false,
      condition: false,
      disableSubmit: false,
      model: {},
      menuhidden: false,
      menuusing: true,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        logisticsNo: { rules: [{ required: true, message: '' }] },
        logisticsDetails: { rules: [{ required: true, message: '' }] },
        logisticsCompany: { rules: [{ required: true, message: '' }] },
      },
      url: {
        fahuo:window._CONFIG['domianSfaURL'] + '/sfaOrderController/deliverGoods',
      },
      dictDisabled: true
    }
  },
  created() {
    this.loadTreeData(0)
  },
  methods: {
    initDictConfig() {

    },
    hanldetwoRules(index) {
      if (index == -1) {
        this.terminalTargetList.push({})
      } else {
        this.terminalTargetList.splice(index, 1)
      }
    },
    loadTreeData(orgCode) {
      var that = this
      // if (this.isAll) {
      queryDepartTreeList().then((res) => {
        if (res.success) {
          that.departTree = []
          for (let i = 0; i < res.result.length; i++) {
            let temp = res.result[i]
            temp.key = temp.orgCode
            this.departTree.push(temp)
          }
        }
      })
    },
    add() {
      this.edit()
    },

    edit(record) {
      console.log(record)
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, Object.keys(this.model)))
      })
    },
    close() {
      this.$emit('close')
      this.disableSubmit = false
      this.visible = false
      this.terminalTargetList = [{}]
    },

    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (this.url.fahuo) {
          that.confirmLoading = true
          let param = Object.assign(this.model, values, )
          param.id = this.model.id
          // param.logisticsCompany = record.logisticsCompany
          // param.logisticsNo = record.logisticsNo
          // param.logisticsDetails = record.logisticsDetails
          postAction(this.url.fahuo, param).then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok')
              that.close()
            } else {
              this.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    },
    handleCancel() {
      this.close()
    },
  }
}
</script>

<style scoped>

</style>
